home *** CD-ROM | disk | FTP | other *** search
/ Delphi Magazine Collection 2001 / Delphi Magazine Collection 20001 (2001).iso / DISKS / Issue33 / clinic / EventU3.PAS < prev    next >
Encoding:
Pascal/Delphi Source File  |  1998-02-04  |  1.1 KB  |  56 lines

  1. unit Eventu3;
  2.  
  3. interface
  4.  
  5. uses
  6.   SysUtils, WinTypes, WinProcs, Messages, Classes, Graphics, Controls,
  7.   Forms, Dialogs, StdCtrls;
  8.  
  9. type
  10.   TForm1 = class(TForm)
  11.     CheckBox1: TCheckBox;
  12.     Button1: TButton;
  13.     procedure Button1Click(Sender: TObject);
  14.     procedure CheckBox1Click(Sender: TObject);
  15.   private
  16.     { Private declarations }
  17.   public
  18.   end;
  19.  
  20. var
  21.   Form1: TForm1;
  22.  
  23. implementation
  24.  
  25. {$R *.DFM}
  26.  
  27. const
  28.   NilMethod: TMethod = (Code: nil; Data: nil);
  29.  
  30. function SetHandler(Handler: TMethod): TMethod;
  31. const
  32.   OldHandler: TMethod = (Code: nil; Data: nil);
  33. begin
  34.   Result := OldHandler;
  35.   OldHandler := Handler
  36. end;
  37.  
  38. procedure TForm1.Button1Click(Sender: TObject);
  39. begin
  40.   CheckBox1.OnClick := TNotifyEvent(SetHandler(TMethod(CheckBox1.OnClick)));
  41.   try
  42.     { This won't trigger the event since it has been disabled }
  43.     CheckBox1.Checked := not CheckBox1.Checked
  44.   finally
  45.     CheckBox1.OnClick := TNotifyEvent(SetHandler(NilMethod))
  46.   end
  47. end;
  48.  
  49. procedure TForm1.CheckBox1Click(Sender: TObject);
  50. begin
  51.   ShowMessage('The checkbox was clicked by the user');
  52.   { Blah, blah, blah }
  53. end;
  54.  
  55. end.
  56.